package com.xiaohong.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiaohong.user.dao.UserAddressMapper;
import com.xiaohong.user.pojo.UserAddress;
import com.xiaohong.user.service.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserAddressServiceImpl implements UserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    /**
     * UserAddress条件+分页查询
     * @param userAddress 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<UserAddress> findPage(UserAddress userAddress, int page, int size){
        // 构建查询条件
        QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<UserAddress>(userAddress);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return userAddressMapper.selectPage(pg, queryWrapper);
    }

    /**
     * UserAddress分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<UserAddress> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return userAddressMapper.selectPage(pg, null);
    }

    /**
     * UserAddress多条件搜索方法
     * @param userAddress
     * @return
     */
    @Override
    public List<UserAddress> findList(UserAddress userAddress){
        // 构建查询条件
        QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<UserAddress>(userAddress);
        // 查询数据
        return userAddressMapper.selectList(queryWrapper);
    }

    /**
     * 根据主键删除
     * @param id
     */
    @Override
    public void delete(Long id){
        userAddressMapper.deleteById(id);
    }

    /**
     * 根据主键修改UserAddress
     * @param userAddress
     */
    @Override
    public void update(UserAddress userAddress){
        userAddressMapper.updateById(userAddress);
    }

    /**
     * 增加UserAddress
     * @param userAddress
     */
    @Override
    public void add(UserAddress userAddress){
        userAddressMapper.insert(userAddress);
    }

    /**
     * 根据主键查询UserAddress
     * @param id
     * @return
     */
    @Override
    public UserAddress findById(Long id){
        return  userAddressMapper.selectById(id);
    }

    /**
     * 查询UserAddress全部数据
     * @return
     */
    @Override
    public List<UserAddress> findAll() {
        return userAddressMapper.selectList(null);
    }
}
